package gomz.pres.admin;

import gomz.pres.CheckBoxList;
import gomz.pres.GUIMain;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

/**
 * Diese Klasse erstellt das GUI des Imports in der Verwaltung.
 * 
 * @author Dilji
 */

public class GUIAImport {

	// all the variables for main panels
	private JPanel plImport;
	private JPanel plImportNord;
	private JScrollPane spImport;

	// all the variables
	private JLabel lbTImportTitle;
	private JLabel lbTsearchData;
	private JTextField tfTpath;
	private JButton btTsearch;
	private JLabel lbTcat;
	private JScrollPane spTcat;
	private CheckBoxList liTcat;
	private JButton btTimport;
	private JButton btTcan;

	/**
	 * Erstellt das GUI fuer den Import
	 * @param categorieList fuellt die Kategorieliste
	 * @return gibt das GUI zurueck
	 */
	public JScrollPane getTab(String[] categorieList) {

		// initialize the panels, add to scrollpane and set position
		this.plImport = new JPanel();
		this.plImportNord = new JPanel();
		this.spImport = new JScrollPane(plImportNord);
		this.plImportNord.setLayout(new BorderLayout());
		this.plImportNord.setBorder(new EmptyBorder((2 * GUIMain.getAbstand()), 0, GUIMain.getAbstand(), 0));
		this.plImportNord.add(plImport, BorderLayout.NORTH);

		// set background of main panels
		this.plImport.setBackground(Color.WHITE);
		this.plImportNord.setBackground(Color.WHITE);

		// initialize the components
		this.lbTImportTitle = new JLabel("Import");
		this.lbTsearchData = new JLabel("Datei suchen (.csv):");
		this.tfTpath = new JTextField();
		this.btTsearch = new JButton("Durchsuchen...");
		this.lbTcat = new JLabel("Kategorie ausw\u00e4hlen:");
		this.liTcat = new CheckBoxList(categorieList);
		this.spTcat = new JScrollPane(liTcat);
		this.btTimport = new JButton("Importieren");
		this.btTcan = new JButton("Zur\u00fccksetzen");

		// FontSize for title
		this.lbTImportTitle.setFont(GUIMain.getTitlefont());
		this.lbTImportTitle.setForeground(GUIMain.getTitleblue());

		// size of scrollpane for list
		this.spTcat.setPreferredSize(new Dimension(295, 200));
		this.spTcat.setMaximumSize(new Dimension(295, 200));
		this.spTcat.setBorder(GUIMain.getBorderColor());

		// size of textField path
		this.tfTpath.setPreferredSize(new Dimension(295, GUIMain.getBtheight()));
		this.tfTpath.setMaximumSize(new Dimension(295, GUIMain.getTfheight()));
		this.tfTpath.setBorder(BorderFactory.createCompoundBorder(GUIMain.getBorderColor(), GUIMain.getBorderInGap()));

		// size of buttons
		this.btTimport.setPreferredSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btTimport.setMaximumSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btTcan.setPreferredSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btTcan.setMaximumSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btTsearch.setPreferredSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btTsearch.setMaximumSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));

		// scroll speed
		this.spImport.getVerticalScrollBar().setUnitIncrement(GUIMain.getScrollspeed());
		this.spTcat.getVerticalScrollBar().setUnitIncrement(GUIMain.getScrollspeed());

		// position of components
		this.plImport.setLayout(new GridBagLayout());
		GridBagConstraints ct = new GridBagConstraints();
		ct.fill = GridBagConstraints.HORIZONTAL; // in x-Achse ausfuellen
		ct.insets = new Insets(GUIMain.getAbstand(), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		ct.anchor = GridBagConstraints.NORTHWEST; // Ausrichtung oben

		ct.gridx = 0; // Spalte 1
		ct.gridy = 0; // Zeile 1
		ct.gridwidth = 2;
		plImport.add(this.lbTImportTitle, ct); // label Title
		ct.gridx = 1; // Spalte 2
		ct.gridy = 0; // Zeile 1
		ct.gridwidth = 1;
		// plImport.add(, ct); // Com

		ct.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), 0, (3 * GUIMain.getAbstand()));
		ct.gridx = 0; // Spalte 1
		ct.gridy = 1; // Zeile 2
		plImport.add(this.lbTsearchData, ct); // Label Datei suchen

		ct.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		ct.gridx = 1; // Spalte 2
		ct.gridy = 1; // Zeile 2
		// plImport.add(, ct); //Com

		ct.insets = new Insets(GUIMain.getAbstand(), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		ct.gridx = 0; // Spalte 1
		ct.gridy = 2; // Zeile 3
		ct.gridwidth = 2;
		plImport.add(this.tfTpath, ct); // Pfad

		ct.gridx = 2; // Spalte 3
		ct.gridy = 2; // Zeile 3
		ct.gridwidth = 1;
		plImport.add(this.btTsearch, ct); // Button durchsuchen...

		ct.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		ct.gridx = 0; // Spalte 1
		ct.gridy = 3; // Zeile 4
		plImport.add(this.lbTcat, ct); // Label Kategorie auswaehlen...

		ct.gridx = 1; // Spalte 2
		ct.gridy = 3; // Zeile 4
		// plImport.add(, ct); // Com

		ct.insets = new Insets(GUIMain.getAbstand(), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		ct.gridx = 0; // Spalte 1
		ct.gridy = 4; // Zeile 5
		ct.gridwidth = 2;
		plImport.add(this.spTcat, ct); // Liste Kategorie

		ct.gridx = 1; // Spalte 2
		ct.gridy = 4; // Zeile 5
		ct.gridwidth = 1;
		// plImport.add(, ct); // Com

		ct.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		ct.gridx = 0; // Spalte 1
		ct.gridy = 5; // Zeile 5
		plImport.add(this.btTimport, ct); // Button Import

		ct.gridx = 1; // Spalte 2
		ct.gridy = 5; // Zeile 6
		plImport.add(this.btTcan, ct); // Button Zuruecksetzten

		return (spImport);
	}

	// ********************************************************************************
	// Getters und Setters
	// ********************************************************************************

	public JButton getBtTsearch() {
		return btTsearch;
	}

	public void setBtTsearch(JButton btTsearch) {
		this.btTsearch = btTsearch;
	}

	public JButton getBtTimport() {
		return btTimport;
	}

	public void setBtTimport(JButton btTimport) {
		this.btTimport = btTimport;
	}

	public JButton getBtTcan() {
		return btTcan;
	}

	public void setBtTcan(JButton btTcan) {
		this.btTcan = btTcan;
	}

	public JTextField getTfTpath() {
		return tfTpath;
	}

	public void setTfTpath(String absolutePath) {
		this.tfTpath.setText(absolutePath);
	}

	public CheckBoxList getLiTcat() {
		return liTcat;
	}

	public void setLiTcat(CheckBoxList liTcat) {
		this.liTcat = liTcat;
	}

}
